Extend the mixed-dependency check to modules as well
authorMatthias Clasen <mclasen@redhat.com>
Tue, 8 Feb 2011 18:49:16 +0000 (13:49 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 8 Feb 2011 18:49:16 +0000 (13:49 -0500)
This helps prevent accidents with GTK_PATH.

gtk/gtkmain.c
gtk/gtkmainprivate.h
gtk/gtkmodules.c

index 515f05bc2fb63655e99a5e7f0637949f112beba3..47af37774a531464fc59e5cff6307577d390a8f3 100644 (file)
@@ -738,20 +738,30 @@ setlocale_initialization (void)
     }
 }
 
-static void
-check_mixed_deps (void)
+/* Return TRUE if module_to_check causes version conflicts.
+ * If module_to_check is NULL, check the main module.
+ */
+gboolean
+_gtk_module_has_mixed_deps (GModule *module_to_check)
 {
   GModule *module;
   gpointer func;
+  gboolean result;
 
-  module = g_module_open (NULL, 0);
+  if (!module_to_check)
+    module = g_module_open (NULL, 0);
+  else
+    module = module_to_check;
 
   if (g_module_symbol (module, "gtk_progress_get_type", &func))
-    {
-      g_error ("GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported");
-    }
+    result = TRUE;
+  else
+    result = FALSE;
+
+  if (!module_to_check)
+    g_module_close (module);
 
-  g_module_close (module);
+  return result;
 }
 
 static void
@@ -765,11 +775,12 @@ do_pre_parse_initialization (int    *argc,
 
   pre_initialized = TRUE;
 
-  check_mixed_deps ();
+  if (_gtk_module_has_mixed_deps (NULL))
+    g_error ("GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported");
 
   gdk_pre_parse_libgtk_only ();
   gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
-  
+
 #ifdef G_ENABLE_DEBUG
   env_string = g_getenv ("GTK_DEBUG");
   if (env_string != NULL)
index f4605d7ccb3b2f9a66efd860f830738efc9496d4..56679389fc8ff42113722b483c8b88d0d1ab085e 100644 (file)
@@ -30,6 +30,8 @@ gboolean _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
 
 gchar *_gtk_get_lc_ctype (void);
 
+gboolean _gtk_module_has_mixed_deps (GModule *module);
+
 G_END_DECLS
 
 #endif  /* __GTK_MAIN_PRIVATE_H__ */
index bd9ba5710fb8e89d786d90951e19f262554d7544..5fa2abf8a13ffd35a42526ff3da7fa6c830730bf 100644 (file)
@@ -26,7 +26,8 @@
 #include "gtksettings.h"
 #include "gtkdebug.h"
 #include "gtkprivate.h" /* GTK_LIBDIR */
-#include "gtkintl.h" 
+#include "gtkmainprivate.h"
+#include "gtkintl.h"
 
 #include <gmodule.h>
 
@@ -236,7 +237,16 @@ find_module (const gchar *name)
     }
 
   module = g_module_open (module_name, G_MODULE_BIND_LOCAL | G_MODULE_BIND_LAZY);
-  g_free(module_name);
+
+  if (_gtk_module_has_mixed_deps (module))
+    {
+      g_warning ("GTK+ module %s cannot be loaded.\n"
+                 "GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported.", module_name);
+      g_module_close (module);
+      module = NULL;
+    }
+
+  g_free (module_name);
 
   return module;
 }
@@ -264,7 +274,7 @@ load_module (GSList      *module_list,
       for (l = gtk_modules; l; l = l->next)
        {
          info = l->data;
-         if (g_slist_find_custom (info->names, name, 
+         if (g_slist_find_custom (info->names, name,
                                   (GCompareFunc)strcmp))
            {
              info->ref_count++;
@@ -273,7 +283,7 @@ load_module (GSList      *module_list,
            }
        }
 
-      if (!success) 
+      if (!success)
        {
          module = find_module (name);
 
@@ -353,8 +363,13 @@ load_module (GSList      *module_list,
        }
     }
   else
-    g_message ("Failed to load module \"%s\": %s", name, g_module_error ());
-  
+    {
+      const gchar *error = g_module_error ();
+
+      g_message ("Failed to load module \"%s\"%s%s",
+                 name, error ? ": " : "", error ? error : "");
+    }
+
   return module_list;
 }